/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import boundary.FLogin;
import boundary.FMain;
import entity.Billing;
import entity.Client;
import entity.Entity;
import entity.Employee;
import components.utils.DefaultToStringComparator;
import components.utils.observer.CollectionManager;
import entity.Address;
import entity.Email;
import entity.ServiceRequest;
import entity.Sample;
import entity.Test;
import entity.DatabaseTest;
import entity.PhoneNumber;
import java.util.ArrayList;
import java.util.TreeSet;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Juan
 */
public class Application {
    
    public static final CollectionManager<Entity> CLIENT_MANAGER =
            new CollectionManager<>(new TreeSet<>(new DefaultToStringComparator()));
    public static final CollectionManager<Entity> DATABASE_TEST_MANAGER = 
            new CollectionManager<>(new TreeSet<>(new DefaultToStringComparator()));
    public static final CollectionManager<Entity> SERVICE_REQUEST_MANAGER =
            new CollectionManager<>(new TreeSet<>(new DefaultToStringComparator()));
    public static final CollectionManager<Entity> EMPLOYEE_MANAGER =
            new CollectionManager<>(new TreeSet<>(new DefaultToStringComparator()));
    
    public static Employee CURRENT_EMPLOYEE;
    public static final FMain F_MAIN = new FMain();
    
    public static void displayEntity(Entity entity) {
        F_MAIN.displayEntity(entity);
    }
    
    public static int sampleID = 0;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Client a = new Client();
        a.setName("Cliente 1");
        a.setIdType(Client.CC);
        a.setId(0);
        a.setType(Client.PERSON);
        a.setIdNum("30315800");
        a.setAbbreviation("CL1");
        a.setCity("Bogotá");
        a.setPhoneNumbers(new ArrayList());
        PhoneNumber phoneNumber = new PhoneNumber();
        phoneNumber.setPhoneNumber("2878095");
        phoneNumber.setType("0000000");
        a.getPhoneNumbers().add(phoneNumber);
        Address aa = new Address();
        aa.setAddress("Calle Falsa 123");
        aa.setType("11000000");
        a.getAddresses().add(aa);
        Email ee = new Email();
        ee.setType("01");
        ee.setEmail("cliente1@dominio.com");
        a.getEmails().add(ee);
        
        Client b = new Client();
        b.setName("Cliente 2");
        b.setId(1);
        b.setIdType(Client.CE);
        b.setType(Client.ENTERPRISE);
        b.setIdNum("32456-8");
        b.setIdType("NIT");
        b.setAbbreviation("CL2");
        b.setCity("Bogotá");
        b.setPhoneNumbers(new ArrayList());
        PhoneNumber abbb = new PhoneNumber();
        abbb.setPhoneNumber("3152168080");
        abbb.setType("000000");
        b.getPhoneNumbers().add(abbb);
        Address a2 = new Address();
        a2.setType("10010000");
        a2.setAddress("Plaza de Bolívar");
        b.getAddresses().add(a2);
        CLIENT_MANAGER.addObject(a);
        CLIENT_MANAGER.addObject(b);
        
        DatabaseTest t = new DatabaseTest();
        t.setName("Análisis 1");
        t.setId(0);
        t.setPrice(10000d);
        t.setHasRush(false);
        DATABASE_TEST_MANAGER.addObject(t);
        DatabaseTest r = new DatabaseTest();
        r.setName("Análisis 2");
        r.setId(1);
        r.setPrice(100000d);
        r.setRushPrice(150000d);
        r.setHasRush(true);
        DATABASE_TEST_MANAGER.addObject(r);
        
        ServiceRequest w = new ServiceRequest();
        w.setId(100);
        w.setClient(a);
        Billing bil = new Billing();
        bil.setBillingPending(true);
        bil.setBillNumber(123);
        w.setBilling(bil);
        w.setDispositionMethod(Sample.DISPOSITION_METHOD_DELIVER);
        SERVICE_REQUEST_MANAGER.addObject(w);
        Sample ss = new Sample();
        ss.setName("Piedra");
        ss.setComments("No dañar");
        ss.setDispositionMethod(Sample.DISPOSITION_METHOD_DELIVER);
        ss.setId(sampleID++);
        ss.setMagnetic(true);
        ss.setPhotographicRecord(true);
        ss.setQuantity(123f);
        ss.setRadioactive(false);
        ss.setState(1);
        ss.getTests().add(new Test(t));
        ss.setServiceRequest(w);
        w.getSamples().add(ss);
        SERVICE_REQUEST_MANAGER.notifyObservers();
        
        CURRENT_EMPLOYEE = new Employee();
        CURRENT_EMPLOYEE.setName("Emp 1");
        CURRENT_EMPLOYEE.setLogin("emp1");
        CURRENT_EMPLOYEE.setPassword("emp1");
        CURRENT_EMPLOYEE.setRole(Employee.ADMIN);
        EMPLOYEE_MANAGER.addObject(CURRENT_EMPLOYEE);
        Employee ab = new Employee();
        ab.setName("Emp 2");
        ab.setLogin("emp2");
        ab.setPassword("emp2");
        ab.setRole(Employee.SECRETARY);
        EMPLOYEE_MANAGER.addObject(ab);
        
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    System.err.println("Look and Feel not found.");
                }
                SwingUtilities.updateComponentTreeUI(F_MAIN);
                F_MAIN.pack();
                new FLogin().setVisible(true);
            }
        });
    }
}
